import { useMainStore } from '@/store'

export const sheetsMaps: DeepReadonly<SheetsMap[]> = [
  {
    name: '混凝土结构',
    path: '/hntjg',
    sheets: [
      {
        title: '混凝土结构-碳化深度检测记录表',
        path: '/thsdjcjlb',
        instruction: '',
      },
      {
        title: '混凝土结构-钢筋位置（电磁感应法）',
        path: '/gjwzdcgyf',
        instruction: '',
      },
    ],
  },
]

export const getCurRecordPath = () => {
  const prefix = '/rw'
  return getInnerDetail(prefix)
}

export const getCurrDescImgPath = () => {
  // const mainStore = useMainStore()
  const prefix = '/static/desc'
  return `${getInnerDetail(prefix)}.png`
  // return `${prefix}/${mainStore.projInfo.fbgc}/${mainStore.projInfo.type}.png`
}

export const getSheetsBy = (groupName: string) => {
  const mid = sheetsMaps.find((item) => item.name === groupName)
  return mid?.sheets || []
}

export const getCurTableTitle = () => {
  const mainStore = useMainStore()
  const tp = mainStore.getCurType()
  const groupName = mainStore.projInfo.gclx
  const res = sheetsMaps.find((item) => item.name === groupName)
  const ttl = res?.sheets.find((item) => item.title === tp)
  return ttl?.path.slice(1).replace(/\//g, '_')
}

export const getTrueGCLX = () => {
  const mainStore = useMainStore()
  const sheetName = mainStore.getCurType()
  const g = mainStore.projInfo.gclx
  const res = sheetsMaps
    .find((item) => item.name === g)
    ?.sheets.find((item) => item.title === sheetName)
  return res?.subclass || g
}

const getInnerDetail = (path: string) => {
  const mainStore = useMainStore()
  const mid = sheetsMaps.find((item) => item.name === mainStore.projInfo.gclx)
  path += mid?.path
  const midPath = mid?.sheets.find(
    (item) => item.title === mainStore.projInfo.type,
  )
  path += midPath?.path
  return path
}

export const getInstruction = () => {
  const mainStore = useMainStore()
  const sheetName = mainStore.getCurType()
  const g = mainStore.projInfo.gclx
  const res = sheetsMaps
    .find((item) => item.name === g)
    ?.sheets.find((item) => item.title === sheetName)
  return res?.instruction || ''
}
